import {
	BaseUrl,
	formatDishesScore
} from "./config"

export function getDishByDishId(dishId) {
	console.log("dishId", dishId);
	return uni.request({
		method: "GET",
		url: BaseUrl + '/dishes/getById',
		data: {
			id: dishId
		}
	}).then(res => {
		console.log("getDishByDishId111", res.data.data);
		return res.data.data;
		// return {
		// 	data: formatDishesScore([res.data.data])[0]
		// }
	})
}

export function getDishesByDishTypeId(dishTypeId) {
	return uni.request({
		method: "GET",
		url: BaseUrl + '/dishes/getByDishTypeId',
		data: {
			dishTypeId,
			pageNumber: 1,
			pageSize: 300
		}
	}).then(res => {

		// console.log("getDishesByDishTypeId", res);
		return res.data.rows
	})
}

export function createDish({
	dishTypeId,
	name,
	description,
	imageurl
}) {
	return uni.request({
		method: "POST",
		url: BaseUrl + "/dishes/create",
		data: {
			dishTypeId,
			name,
			description,
			imageurl
		}
	}).then(res => res.data)
}

export function updateDish({
	id,
	name,
	dishTypeId,
	description,
	imageurl
}) {
	return uni.request({
		method: "PUT",
		url: BaseUrl + "/dishes/update",
		data: {
			id,
			name,
			dishTypeId,
			description,
			imageurl
		}
	}).then(res => res.data)

}

export function deleteDishById(dishId) {
	console.log("deleteDishById", dishId);
	return uni.request({
		method: "DELETE",
		url: BaseUrl + "/dishes/delete?id=" + dishId,
		// data: {
		// 	id: dishId
		// }
	}).then(res => res.data)
}